<?php

/**
 * Subclass for representing a row from the 'works' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Works extends BaseWorks
{
    const TYPE_PROJECT          = 1;
    const TYPE_WORK             = 2;
    const TYPE_FRIEND           = 3;
    public function hydrate(ResultSet $rs, $startcol = 1)
    {
        $this->setCulture(sfContext::getInstance()->getUser()->getCulture());
        return parent::hydrate($rs, $startcol);
    }
    
    public static function getTypesList()
    {
        return array( __('project') => self::TYPE_PROJECT
                    , __('work') => self::TYPE_WORK
                    , __('friend') => self::TYPE_FRIEND );
    }
    
    public function getFirstImage()
    {
        $c = new Criteria();
        $c->addDescendingOrderByColumn(FilesPeer::PRIORITY);
        $c->add(FilesPeer::OBJ_TYPE, MyConstants::TYPE_WORKS);
        $c->add(FilesPeer::OBJ_ID, $this->id);
        $photo = FilesPeer::doSelectOne($c);
        return $photo;
    }
}
